package com.example.ordersystem.dao;


import com.example.ordersystem.domain.Customer;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface CustomerDAOByMybatis {

    /**
     * 顾客登录检查
     *
     * @param num 账户
     * @param pwd 密码
     * @return 顾客实体
     */
    @Select("select * from customer where num=#{num} and pwd=#{pwd}")
    Customer customerLoginCheck(@Param("num") int num, @Param("pwd") String pwd);

    /**
     * 插入一条顾客记录
     *
     * @param customer 待插入的顾客
     * @return 自动生成的账号
     */
    @Insert("insert into customer(name,pwd,tel) values (#{name},#{pwd},#{tel})")
    @Options(useGeneratedKeys = true, keyProperty = "num", keyColumn = "num")
    int register(Customer customer);


    /**
     * 在顾客表中查询，手机号是否已经注册
     * @param tel 手机号
     * @return 查找到的手机号
     */
    @Select("select * from customer where tel=#{tel}")
    Customer findByTel(@Param("tel") String tel);

    @Select("select * from customer where tel=#{tel}")
    Customer findCustomerByTel(@Param("tel") String tel);

    /**
     * 顾客修改密码
     * @param num 顾客账号
     * @param pwd 新的密码
     */
    @Update("update customer set pwd=#{pwd} where num=#{num}")
    void modifyPass(@Param("num") int num, @Param("pwd") String pwd);
}
